<!DOCTYPE html>
<!-- /* -->
<!--  * Copyright 2016-2021 the original author.All rights reserved. -->
<!--  * AiTeaSoft.com-->
<!--  * Kingstar(aiteasoft@163.com) -->
<!--  * The license,see the LICENSE file. -->
<!--  * Create on 2021-04-14 16:57:23 -->
<!--  * v1.9.02 -->
<!--  */ -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<style type="text/css">
  .STYLE1 {color: #FF0000}
  .template{display: none; }
</style>

	<title>scores</title>
	<link rel="stylesheet" type="text/css" href="../../css/je/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../../css/je/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="../../css/je/themes/color.css">
	<link rel="stylesheet" type="text/css" href="../../css/je/themes/demo.css">
	<script type="text/javascript" src="../../js/jquery.js"></script>
<!-- 	<script type="text/javascript" src="../../js/jquery.easyui.min.js"></script> -->
	<script type="text/javascript" src="../../js/jqeEx.js"></script> 
	<script type="text/javascript" src="../../js/js-ex.js"></script>
<!-- 	<script type="text/javascript" src="../../js/jquery.edatagrid.js"></script> -->
<!-- 	<script type="text/javascript" src="../../js/suid-jq.js"></script> -->
<script type="text/javascript" src="../../js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../js/jqeEx.js"></script>
	<script type="text/javascript" src="../../js/template-web.js"></script>



<script type="text/javascript">
		$(function(){
			
			$.ajaxSettings.async = false;
			
			$.getJSON(rootpath+'/assignclass/classno', function(data){
				var html = template('template1', data);
				document.getElementById('result1').innerHTML = html;
				if (data.errorMsg) {
					$.messager.show({
						title : 'Error',
						msg : data.errorMsg
					});
				} 
		 });
			
			
			
			$.getJSON(rootpath+'/course/all', function(data){
				var html = template('template', data);
				document.getElementById('result').innerHTML = html;
				if (data.errorMsg) {
					$.messager.show({
						title : 'Error',
						msg : data.errorMsg
					});
				} 
		});
			
		$.ajaxSettings.async = true;	
			
		});
		
		
		

	function gen() {

		// 			alert("test");
		// 			var oldTxt=$("input[name='classno']").val();

		var v = [];
       
		$("input[name='classno']:checked").each(function() {
			v.push($(this).val());
// 			 title = $("input:checkbox[name='sort']:checked").next().text();
			
		});
// 		alert(v.length == 0 ? '你还没有选择任何内容！' : v);
        if(v.length == 0) {
        	alert("班级不能为空!");
        	return ;
        }
//         alert(v);
        
		var course1 = [];
		 var txt=[];		
		$("input[name='course']:checked").each(function() {
			course1.push($(this).val());
			txt.push($(this).next().text());
		});
        if(course1.length == 0) {
        	alert("课程不能为空!");
        	return ;
        }
//         alert(course1);
//          alert(txt);
         
        var data={
        		classno:v,
        		subjectno:course1,
        		subject:txt
        }
        
        var html=template('template2',data);
        document.getElementById('result2').innerHTML = html;
       
	}
	
	function assign() {
		
		var initObj = {};
		if ($('#term').val().trim() != "") {
			initObj.term = $('#term').val().trim();
		}
		
	var arraydata = getArrayForm("arrayForm", initObj);
	var url = '../../assigncourse/assign';
	
	alert(arraydata);
	
	$.ajax({
		type : 'post',
		url : url,
		dataType : 'json',
		contentType : "application/json", 
		data : JSON.stringify({
			assigncourses : arraydata
		}), //assigncourses  要对应springmvc的对象名称

		success : function(result) {
			if (result.errorMsg) {
				$.messager.show({
					title : 'Error',
					msg : result.errorMsg
				});
			} else {
				$.messager.show({
					title : 'Successfully',
					msg : 'Successfully!'
				});
			}
		},
	error:function(e){  
        console.log(e);  
        alert(e.status+"  :  "+e.statusText);
    },

	});
	
	}
	
	
</script>


</head>
<body>
学期:
  <select name="term" id="term">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
  </select>
  <br><br>
	<div id="result1"></div>
	<textarea id="template1" class="template">
	{{each rows value i}}	 
	  <input type="checkbox" name="classno"  id="classno{{i}}" value="{{value[0]}}" > <label for="classno{{i}}">{{value[0]}}</label>  <br>   
	{{/each}}
	</textarea>
	<br>
	<div id="result"></div>
	<textarea id="template" class="template">
	{{each rows value i}}	 
	  <input type="checkbox" name="course"  id="course{{i}}" value="{{value.subjectno}}" > <label for="course{{i}}">{{value.subject}}</label>    
	{{if i!=0 && i%4==0}}
	<br>
	{{/if}}
	{{/each}}
	</textarea>
	
	<br>
	 <input type="button" name="button2" id="button2" value="生成" onclick="gen()">
	 <br><br>
	 
	 
	<div id="result2"></div>
	<textarea id="template2" class="template">
	<form  name="form{{j}}" class="arrayForm" method="post">
	<table>
	<th> 班级 </th>  <th> 课程编号  </th>  <th> 课程名称  </th> <th> 老师 </th>
	<%for(var i=0;i<classno.length;i++){ %>
	
	<%for(var j=0;j<subjectno.length;j++){ %>
	 
	<tr>
	<td> <%=classno[i]%>  <input type="hidden" name="classno"  value="<%=classno[i]%>"/></td>  
	<td> <%=subjectno[j]%>  <input type="hidden" name="subjectno"  value="<%=subjectno[i]%>"/></td>  
	<td> <%=subject[j]%> <input type="hidden" name="subject" value="<%=subject[i]%>"/></td>   </td> 
	
	<td> 
	
	  <label>
  <select name="teacherno">
  
  	{{if subjectno[j]=='30001'}}
    <option value="60009">语文老师1</option>
    <option value="60010">语文老师2</option>
	{{else if subjectno[j]=='30002'}}
     <option value="60011">数学老师1</option>
    <option value="60012">数学老师2</option>
    {{/if}}
  </select>
  </label>
	 </td>
	</tr>
	
	
	<%}%>
	
	<%}%>
	
	</table>
	
	</form>
	
		<br>
	 <input type="button" name="button3" id="button3" value="生成排课信息" onclick="assign()">
	 <br><br>
	
	</textarea>
	 
	 
</body>
</html>